﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;

namespace HirelSeriesH
{
    public partial class EMForm : UIForm
    {
        public System.Timers.Timer Timer = new System.Timers.Timer();
        public EMForm()
        {
            InitializeComponent();
            //使线程可以调用窗体控件
            CheckForIllegalCrossThreadCalls = false;

            Timer.Interval = 1000 * 3;
            Timer.Elapsed += new ElapsedEventHandler(Timer1_Tick);
            if (Global.Global.NEMcomm != null)
            {
                Timer.Start();
            }
        }

        private void Timer1_Tick(object sender, ElapsedEventArgs e)
        {
            TBdy1.Text = Global.Global.NEMcomm.Voltage;
            TBdl1.Text = Global.Global.NEMcomm.Current;
            TBgl1.Text = Global.Global.NEMcomm.Power;
            TBdy2.Text = Global.Global.NEMcomm.Voltage2;
            TBdl2.Text = Global.Global.NEMcomm.Current2;
            TBgl2.Text = Global.Global.NEMcomm.Power2;
            TBdy3.Text = Global.Global.NEMcomm.Voltage3;
            TBdl3.Text = Global.Global.NEMcomm.Current3;
            TBgl3.Text = Global.Global.NEMcomm.Power3;
        }
        
        private void EMForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Timer.Stop();
        }

        private void BtBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
